using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Workflow2211A.Application.DTO.Inputs.IndependentBilling
{
    /// <summary>
    /// 开单申请输入DTO
    /// </summary>
    public class PrescriptionApplicationDTO
    {
        /// <summary>
        /// 院区ID
        /// </summary>
        [Required(ErrorMessage = "院区ID不能为空")]
        public long HospitalAreaId { get; set; }

        /// <summary>
        /// 用户
        /// </summary>
        [Required(ErrorMessage = "用户不能为空")]
        [StringLength(50, ErrorMessage = "用户名最大长度为50")]
        public string Names { get; set; }

        /// <summary>
        /// 开单原因
        /// </summary>
        [Required(ErrorMessage = "开单原因不能为空")]
        [StringLength(500, MinimumLength = 20, ErrorMessage = "开单原因长度必须在20-500字之间")]
        public string Reason { get; set; }

        /// <summary>
        /// 开单明细项目
        /// </summary>
        [Required(ErrorMessage = "至少需要一个开单项目")]
        public List<PrescriptionDetailDTO> Details { get; set; } = new List<PrescriptionDetailDTO>();

        /// <summary>
        /// 合计金额（只读）
        /// </summary>
        public decimal TotalAmount => Details?.Sum(d => d.Price * d.Quantity) ?? 0;
    }

    /// <summary>
    /// 开单明细输入DTO
    /// </summary>
    public class PrescriptionDetailDTO
    {
        /// <summary>
        /// 项目类型：1-药品，2-检查，3-检验
        /// </summary>
        [Required(ErrorMessage = "项目类型不能为空")]
        [Range(1, 3, ErrorMessage = "项目类型必须为1-3之间的值")]
        public int ItemType { get; set; }

        /// <summary>
        /// 项目ID
        /// </summary>
        [Required(ErrorMessage = "项目ID不能为空")]
        public long ItemId { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        [Required(ErrorMessage = "数量不能为空")]
        [Range(1, int.MaxValue, ErrorMessage = "数量必须大于0")]
        public int Quantity { get; set; }

        /// <summary>
        /// 项目名称
        /// </summary>
        public string ItemName { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        public decimal Price { get; set; }

        /// <summary>
        /// 总价
        /// </summary>
        public decimal TotalPrice => Price * Quantity;

        /// <summary>
        /// 是否为处方药
        /// </summary>
        public bool IsPrescription { get; set; }

        /// <summary>
        /// 限购数量
        /// </summary>
        public int LimitQuantity { get; set; }

        /// <summary>
        /// 单位（剂/次/盒等）
        /// </summary>
        public string Unit { get; set; }

        /// <summary>
        /// 库存状态信息
        /// </summary>
        public string StockStatus { get; set; } = "";

        /// <summary>
        /// 库存是否充足
        /// </summary>
        public bool IsStockEnough { get; set; } = true;

        /// <summary>
        /// 限购状态信息
        /// </summary>
        public string LimitStatus { get; set; } = "";

        /// <summary>
        /// 是否在限购范围内
        /// </summary>
        public bool IsWithinLimit { get; set; } = true;
    }
} 